<?php
/**
 * 商户端优惠券管理
 */

namespace App\store\controllers\shops;

use App\store\controllers\StoreBaseController;
use App\store\models\ShopModel;
use App\store\services\ShopServices;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class ShopController extends StoreBaseController
{

    private  $class_name = 'Shops';

    /**
     * 店铺信息
     */
    public function getShopsInfo(Request $request)
    {
        //获取数据
        $data = self::getStoreData($this->class_name, 'getShopsInfo', 2);
        if ($data) {
            return $data;
        }
        $data = $request->all();
        $validator = Validator::make(
            $data,
            ShopModel::rules(),
            ShopModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return $this->errorJson($msg[0], []);
        }
        $list = ShopServices::getShopInfo($data);
        return successJson('ok', $list);
    }

    /**
     * 修改店铺信息
     */
    public function updateShopsInfo(Request $request)
    {
        //获取数据
        $data = self::getStoreData($this->class_name, 'updateShopsInfo', 2);
        if ($data) {
            return $data;
        }
        $data = $request->all();
        $validator = Validator::make(
            $data,
            ShopModel::update_rules(),
            ShopModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return $this->errorJson($msg[0], []);
        }
        $list = ShopServices::updateShopInfo($data);
        return successJson('ok', $list);
    }

}

